package com.zjj.jvm2.memAllocation;

import org.openjdk.jol.info.ClassLayout;

/**
 * @author zhanglei.zjj
 * @description 演示 jol-core 工具计算对象内存大小，测试指针压缩
 * -XX:+UseCompressedOops 压缩实例数据引用类型指针（默认开启），-XX:-UseCompressedOops 参数关闭
 * -XX:+UseCompressedClassPointers 压缩对象头的klass pointer（默认开启），-XX:-UseCompressedClassPointers 参数关闭
 * @date 2023/3/8 21:32
 */
public class CalculateObjectSizeSample {
    public static void main(String[] args) {
        ClassLayout objectLayout = ClassLayout.parseInstance(new Object());
        System.out.println("object: " + objectLayout.toPrintable());

        System.out.println();

        ClassLayout arrayLayout = ClassLayout.parseInstance(new int[]{});
        System.out.println("array: " + arrayLayout.toPrintable());

        System.out.println();

        ClassLayout aLayout = ClassLayout.parseInstance(new A());
        System.out.println("a: " + aLayout.toPrintable());
    }
}

class A {
    private int id;
    private String name;
    private byte b;
    Object o;
}
